package com.yidu.hbatsft.action;

import com.yidu.hbatsft.domain.AtsSchemeAudit;
import com.yidu.hbatsft.service.AtsSchemeAuditService;
import com.yidu.utils.Message;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/AtsSchemeAuditController")
public class AtsSchemeAuditController {
    /**
     * 审核表的service
     */
    @Resource
    AtsSchemeAuditService service;

    /**
     * 增加或修改的方法
     * @param atsSchemeAudit
     * @return
     */
    @RequestMapping("addorupdate")
    @ResponseBody
    public Message addorupdate(AtsSchemeAudit atsSchemeAudit){
        int rows=0;
        Date date=new Date();
        /*设置日期格式yyy-MM-dd hh:mm:ss*/
        SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM-dd");
        atsSchemeAudit.setAuTime(sdf.format(date));
        //查询此方案是否提交过
        AtsSchemeAudit audit=service.finbysaId(atsSchemeAudit.getSaId());
        if(audit!=null){
            rows=service.updateByPrimaryKeySelective(atsSchemeAudit);
        }else{
            rows=service.insertSelective(atsSchemeAudit);
        }
        Message message = new Message();
        if(rows>0){
            message.setNum(1);
        }else {
            message.setNum(0);
        }
        return message;
    }

    /**
     * 根据业务id查询
     * @param id
     * @return
     */
    @RequestMapping("finbysaid")
    @ResponseBody
    public AtsSchemeAudit finbysaid(String id){
        AtsSchemeAudit atsSchemeAudit = service.finbysaId(id);
        return atsSchemeAudit;
    }
}
